package com.haohe.wx.wechat.common;

import java.util.Date;
import org.apache.commons.lang.StringUtils;

public class Token {
	private String token;
	private long expires;
	private long tokenTime;
	private int redundance = 10000;

	public boolean isValid() {
		if (StringUtils.isBlank(this.token))
			return false;
		if (this.expires <= 0L) {
			return false;
		}
		if (isExpire())
			return false;
		return true;
	}

	private boolean isExpire() {
		Date currentDate = new Date();
		long currentTime = currentDate.getTime();
		long expiresTime = this.expires * 1000L - this.redundance;

		if (this.tokenTime + expiresTime > currentTime)
			return false;
		return true;
	}
}
